<?php
    const HOST = 'localhost';
    const USERNAME = 'root';
    const PASSWORD = 'root';
    const DBNAME = 'shopping';

    $conn = mysqli_connect(HOST,USERNAME,PASSWORD,DBNAME);
    // var_dump($conn);

    if($conn->connect_error){
        die("连接失败:".$conn->connect_error);
    }
    $name=$_REQUEST['name'];
    // 查询数据库
    mysqli_select_db($conn,"shopping");
    $sql = "SELECT * FROM user_coupon WHERE `username` LIKE '$name' ";
    

    mysqli_query($conn,"set names 'utf8'");
    $result = mysqli_query($conn,$sql);

$arrcouponextend = array();
    
    if(mysqli_num_rows($result)>0){
        // 循环遍历，拿到每一条数据
        while($row = mysqli_fetch_assoc($result)){
            
            array_push($arrcouponextend,$row);
        }
        $res = array(
            'couponextend'=> $arrcouponextend
          );
          echo json_encode($res);

     
    }
?>